<?php
  //require 'init.php';
$sql = "SELECT g.id gid, g.name gname, g.price, g.cate_id, i.name iname FROM ".PRE."goods g, ".PRE."image i WHERE g.id = i.goods_id AND i.is_face=1 AND g.stock > 0 AND g.status = 1 ORDER BY g.price DESC";
//echo $sql; exit;
$result = mysql_query( $sql );
if ( $result && mysql_num_rows( $result ) > 0 ) {
	$goodslist = array();
	while ( $rows = mysql_fetch_assoc( $result ) ) {
		$goodslist[] = $rows;
	}
}
//shuffle( $goodslist );

$key = array_rand( $goodslist, 4 );

//var_dump( $key );exit;
$n=0;
$num = 9000;
foreach ( $key as $k ){
	$prize_arr[$n]['id'] = $n + 1;
	$img = UPLOAD_URL;
	$img .= substr( $goodslist[$k]['iname'], 0, 4 ) . '/';
	$img .= substr( $goodslist[$k]['iname'], 4, 2 ) . '/';
	$img .= substr( $goodslist[$k]['iname'], 6, 2 ) . '/';
	$img .= $size[2] . 'x' . $size[3] . '_' . $goodslist[$k]['iname'];
	$prize_arr[$n]['prize'] = '<img src="' . $img . '" title="' . $goodslist[$k]['gname'] . '" height="180">';
	$prize_arr[$n]['v'] = floor( 1000 / $goodslist[$k]['price'] );
	$num -= $prize_arr[$n]['val'];
	$prize_arr[$n]['cate_id'] = $goodslist[$k]['cate_id'];
	$prize_arr[$n]['gid'] = $goodslist[$k]['gid'];
	$prize_arr[$n]['gname'] = $goodslist[$k]['gname'];
	$n++;
} 
$prize_arr[4] = array( 'id' => 5, 'prize' => '恭喜抽到10积分', 'v' => '1000' );
$prize_arr[5] = array( 'id' => 6, 'prize' => '下次可能就中了', 'v' => $num );
$_SESSION['prize'] = $prize_arr;
//var_dump( $prize_arr );exit;

?>
  <div class="credits fr">
                <h3>积分抽奖</h3>
                <p>每次抽奖需要10积分（你目前的积分为<font color="green" size="3"><?php echo $_SESSION['home']['credits']; ?></font>）</p>
				<p>一等奖：<a href="view.php?id=<?php echo $prize_arr[0]['cate_id']?>&gid=<?php echo $prize_arr[0]['gid']?>"><?php echo $prize_arr[0]['gname']?></a><br>
					二等奖：<a href="view.php?id=<?php echo $prize_arr[1]['cate_id']?>&gid=<?php echo $prize_arr[1]['gid']?>"><?php echo $prize_arr[1]['gname']?></a><br>
					三等奖：<a href="view.php?id=<?php echo $prize_arr[2]['cate_id']?>&gid=<?php echo $prize_arr[2]['gid']?>"><?php echo $prize_arr[2]['gname']?></a><br>
					四等奖：<a href="view.php?id=<?php echo $prize_arr[3]['cate_id']?>&gid=<?php echo $prize_arr[3]['gid']?>"><?php echo $prize_arr[3]['gname']?></a><br>
					五等奖：10积分<br><br>
				</p>
                
                <ul id="prize">
				<?php if($_SESSION['home']['credits']>=10):?>
                    <li class="red" title="点击抽奖">1</li>
                    <li class="green" title="点击抽奖">2</li>
                    <li class="blue" title="点击抽奖">3</li>
                    <li class="purple" title="点击抽奖">4</li>
                    <li class="olive" title="点击抽奖">5</li>
                    <li class="brown" title="点击抽奖">6</li>
				<?php else:?>
					您的积分不足无法抽奖！
				<?php endif;?>
                </ul>
                <div style="clear:both; padding-top:20px"><a href="javascript:void(0)" id="viewother">翻开其他</a><a href="javascript:void(0);" id="repeat">再来一次</a></div>
                <div id="data"></div>

            </div>
        
        
       